package com.example.administrator.myapplication;

import android.os.Bundle;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.example.administrator.myapplication.utils.MyUtils;

import java.util.Map;

/**
 * 关于数据存储的Activity
 */
public class Main3Activity extends AppCompatActivity {

    private EditText username;
    private EditText password;
    private CheckBox remember;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        username = findViewById(R.id.am3_et_un);
        password = findViewById(R.id.am3_et_pw);
        remember = findViewById(R.id.am3_cb_rm);
        Map<String, Object> info = MyUtils.getInfo(Main3Activity.this);
        if(info!=null){
            String ustr= (String) info.get("username");
            String pstr= (String) info.get("password");
            username.setText(ustr);
            password.setText(pstr);
        }

    }

    public void login(View view){
        String uStr=username.getText().toString();
        String pStr=password.getText().toString();
        if(TextUtils.isEmpty(uStr)||TextUtils.isEmpty(pStr)){
            Toast.makeText(Main3Activity.this,"用户名密码不能为空",Toast.LENGTH_SHORT).show();
        }else{
            if(remember.isChecked()){
                MyUtils.saveInfo(Main3Activity.this,uStr,pStr);
            }
        }
    }

}
